package com.wen.controller;

import com.wen.api.MediaManageApi;
import com.wen.pojo.RspResult;
import com.wen.service.MinioService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.Map;


@RestController
@RequestMapping("/file")
public class MinioController implements MediaManageApi {

    @Autowired
    private MinioService minioService;

    @RequestMapping("/register")
    public RspResult register(String fileMd5, String fileName, Long fileSize, String mimetype, String fileExt) {
        return minioService.register(fileMd5,fileName,fileSize,mimetype,fileExt);
    }

    @RequestMapping("/checkchunk")
    public RspResult checkChunk(String fileMd5, Integer chunk, Integer chunkSize) {
        return minioService.checkChunk(fileMd5,chunk,chunkSize);
    }

    @RequestMapping("/uploadchunk")
    public RspResult uploadChunk(MultipartFile file, String fileMd5, Integer chunk) {
        return minioService.uploadChunk(file,fileMd5,chunk);
    }

    @RequestMapping("/mergechunks")
    public RspResult mergeChunks(String fileMd5, String fileName, Long fileSize, String mimetype, String fileExt) {
        return minioService.mergeChunks(fileMd5,fileName,fileSize,mimetype,fileExt);
    }

    @RequestMapping("/download")
    public void download(HttpServletResponse response, String bucketName, String filename) {
         minioService.download(response,bucketName,filename);
    }


    @RequestMapping("/delete")
    public RspResult delete(String bucketName,String filename) {
        return minioService.delete(bucketName,filename);
    }

    @RequestMapping("/preview")
    public void preview(HttpServletResponse response,String bucketName,String filename) throws Exception {

      minioService.preview(response,bucketName,filename);
    }


    /*public Map upImages(MultipartFile file, String fileMd5) {
        return null;
    }*/
}
